package com.dianxin.smartpark.service.device.impl;

import com.chinatelecom.response.common.CommonResponseBody;
import com.chinatelecom.response.utils.Convert;
import com.chinatelecom.response.utils.StringUtils;
import com.dianxin.acl.api.acl.AclFileRpcService;
import com.dianxin.acl.api.dto.SysFileDTO;
import com.dianxin.acl.api.qo.SysFileQO;
import com.dianxin.device.api.device.SmartParkDeviceRpcService;
import com.dianxin.device.api.device.dto.SmartDeviceDTO;
import com.dianxin.device.api.device.qo.SmartDeviceNoAclRpcQO;
import com.dianxin.device.api.device.qo.SmartDeviceRpcQO;
import com.dianxin.smartpark.service.device.SmartParkDeviceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangkai
 */
@Service
public class SmartParkDeviceImpl implements SmartParkDeviceService {

    @Resource()
    private SmartParkDeviceRpcService smartParkDeviceRpcService;

    @Resource
    private AclFileRpcService aclFileRpcService;

    @Override
    public CommonResponseBody<Boolean> saveDevice(SmartDeviceDTO vo) {
        return smartParkDeviceRpcService.saveDevice(vo);
    }

    @Override
    public CommonResponseBody<Boolean> updateDevice(SmartDeviceDTO vo) throws Exception {
        return smartParkDeviceRpcService.updateDevice(vo);
    }

    @Override
    public CommonResponseBody<Boolean> deleteDevice(SmartDeviceDTO vo) throws Exception {
        return smartParkDeviceRpcService.deleteDevice(vo);
    }

    @Override
    public CommonResponseBody<List<SmartDeviceDTO>> getDevices(SmartDeviceRpcQO qo) throws Exception {
        return smartParkDeviceRpcService.getDevices(qo);
    }

    @Override
    public CommonResponseBody<Boolean> rebootDevice(SmartDeviceRpcQO qo) throws Exception {
        return smartParkDeviceRpcService.rebootDevice(qo);
    }

    @Override
    public CommonResponseBody<SmartDeviceDTO> getDeviceNoAcl(SmartDeviceNoAclRpcQO qo) throws Exception {
        CommonResponseBody<SmartDeviceDTO>  smartDeviceDTOCommonResponseBody =  smartParkDeviceRpcService.getDeviceNoAcl(qo);
        if(smartDeviceDTOCommonResponseBody.isSuccess() && StringUtils.isNotNull(smartDeviceDTOCommonResponseBody.getData())){
            SysFileQO sysFileQO = new SysFileQO();
            sysFileQO.setBusiType(9999);
            sysFileQO.setTenantId(smartDeviceDTOCommonResponseBody.getData().getTenantId());
            CommonResponseBody<List<SysFileDTO>> commonResponseBody  = aclFileRpcService.getFileList(sysFileQO);
            if(commonResponseBody.isSuccess() && StringUtils.isNotEmpty(commonResponseBody.getData())){
                smartDeviceDTOCommonResponseBody.getData().setQrImgId(Convert.toStr(commonResponseBody.getData().get(0).getId()));
            }
        }
        return smartDeviceDTOCommonResponseBody;
    }
}
